const fs = require("fs");

function read(path) {
    return new Promise((resolve, reject) => {
        fs.readFile(path, function (err, chunk) {
            if (err) {
                console.log("文件读取失败!");
                reject(err.message);
            }

            resolve(chunk.toString());
        })
    })

}

function write(path, data) {
    return new Promise((resolve, reject) => {
        fs.writeFile(path, data, (err) => {
            if (err) {
                reject(false);
            }
            resolve(true);
        })
    })
}

module.exports = {
    read,
    write
}